﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OFB.BLL.Context;
using System.Data;

namespace OFB.BLL.Repository
{
    public class ReportFeedbackResultBLL
    {
        private ReportFeedbackResultContext context;

        public ReportFeedbackResultBLL()
        {
            context = new ReportFeedbackResultContext();
        }

        public ViewModel.ReportFeedbackResultViewModel GetFeedbackResult(int topicId, int courseId, DateTime fromDate, DateTime toDate)
        {
            IDataParameter para = context.FeedbackResult.BuildParameter("TraineeDoFeedback", DbType.Int32, ParameterDirection.Output);
            //ViewModel.ReportFeedbackResultViewModel result = null;
            if (context.FeedbackResult.Init("Report_GetFeedbackResult",
                context.FeedbackResult.BuildParameter("TopicId", System.Data.DbType.Int32, topicId),
                context.FeedbackResult.BuildParameter("CourseId", System.Data.DbType.Int32, courseId),
                context.FeedbackResult.BuildParameter("FromDate", System.Data.DbType.DateTime, fromDate),
                context.FeedbackResult.BuildParameter("ToDate", System.Data.DbType.DateTime, toDate)
                ).Map().Get()!=null)
            {
                ViewModel.ReportFeedbackResultViewModel result = context.FeedbackResult.Init("Report_GetFeedbackResult",
                context.FeedbackResult.BuildParameter("TopicId", System.Data.DbType.Int32, topicId),
                context.FeedbackResult.BuildParameter("CourseId", System.Data.DbType.Int32, courseId),
                context.FeedbackResult.BuildParameter("FromDate", System.Data.DbType.DateTime, fromDate),
                context.FeedbackResult.BuildParameter("ToDate", System.Data.DbType.DateTime, toDate),
                para
                )
                .Map()
                .IncludeCollection<ViewModel.ReportFeedbackDetailViewModel>("FeedbackDetail", true)
                .IncludeCollection<ViewModel.ReportFeedbackDetailViewModel>("QuestionTemplate", true)
                .Get();

                if (result != null)
                {
                    result.TraineeDoFeedback = (int)para.Value;
                    return result;
                }
            }

            return null;
        }
    }
}
